
<script type="text/javascript">
    function replaceURLWithHTMLLinks(text) {
        /* HTML Link pattern */
        var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
        text = text.replace(exp,'<a href="$1">$1</a>');
        /* Email Link patten */
        var emailPattern = /(^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9]{2,4}$)/ig;
        text = text.replace(emailPattern,'<a href="mailto:$1">$1</a>');
        return text;
    }

    $().ready(function(){
        $('.properties-show-block .prop-display-listing tbody td').each(function(){
            $(this).html(replaceURLWithHTMLLinks($(this).html()));
        });
    });
</script>
<h1><?php echo $collection_item->getCollectionName() ?></h1>
<?php if ($collection_item->getDeletedAt() != null): ?>
<?php slot('page_title', 'Collection Archived - ' . sfConfig::get('app_general_system_name')) ?>
    <p id="archivedMessage">
        This collection has been archived and is no longer available.
        <a href="<?php echo url_for('CollectionRestore', array('uin' => $collection_item->getUin())) ?>" id="restore">Restore</a>
    </p>
<?php else: ?>
<?php slot('page_title', $collection_item->getCollectionName() . ' - ' . sfConfig::get('app_general_system_name')) ?>
        <div class="details-summary-block">
            <p class="details-summary" >
        <?php echo $collection_item->getCollectionType() ?>,  Last Updated <?php echo $collection_item->getUpdatedAt() ?>
        <?php if ($collection_item->getVisibilityLevelUin()): ?>
            , Visibility <?php echo $collection_item->getVisibilityLevel() ?>
        <?php endif; ?>
        </p>
        <p class="details-tagged-with">
            Tagged with
            <a href="<?php echo url_for('TagBrowse', array('tags' => $collection_item->getTagString())) ?>">
            <?php echo $collection_item->getTagString() ?>
        </a>
    </p>
</div>
<div class="show-block properties-show-block">
    <h2>Properties</h2>


    <?php if (($collection_item->getCollectionPropertiesSorted()->count() > 0) || ($collection_item->getApplicableStart() != null) || ($collection_item->getApplicableEnd() != null)): ?>
                <table class="prop-display-listing">
                    <tbody>
            <?php if ($collection_item->getApplicableStart() != null): ?>
                    <tr>
                        <th>Applicable Start Date</th>
                        <td>
                    <?php echo $collection_item->getApplicableStart() ?>
                </td>
            </tr>
            <?php endif; ?>

            <?php if ($collection_item->getApplicableEnd() != null): ?>
                        <tr>
                            <th>Applicable End Date</th>
                            <td>
                    <?php echo $collection_item->getApplicableEnd() ?>
                    </td>
                </tr>
            <?php endif; ?>

            <?php $lastPropertyDetailName = '' ?>
            <?php foreach ($collection_item->getCollectionPropertiesSorted() as $property): ?>
                            <tr>
                                <th><?php /*
                             * Don't repeat the heading if its the same as the previous item in the list*
                             */
                            if ($property->getPropertyDetail()->getTypeName() != $lastPropertyDetailName): ?>
                    <?php echo $property->getPropertyDetail() ?>
                    <?php $lastPropertyDetailName = $property->getPropertyDetail()->getTypeName(); ?>
                    <?php endif; ?>

                            </th>
                            <td><?php echo $property->getPropertyValue() ?></td>
                        </tr>
            <?php endforeach; ?>
                            </tbody>
                        </table>
    <?php else: ?>
                                    <p class="empty-block-message">This collection does not have any properties</p>
    <?php endif; ?>
                                </div>
                                <div class="show-block relations-show-block">
                                    <h2>Related Collections</h2>
    <?php if (($collection_item->getCollectionRelationsSorted()->count() + $collection_item->getRelatingCollectionsSorted()->count()) > 0): ?>

    <?php $lastRelationTypeHeader = '' ?>
    <?php foreach ($collection_item->getCollectionRelationsSorted() as $relation): ?>


    <?php if ($lastRelationTypeHeader != $relation->getRelationType()->getTypeName()): ?>

    <?php if ($lastRelationTypeHeader != ''): ?>
                                                </ul>
<?php endif; ?>       

                                                    <h3><?php echo $relation->getRelationType() ?></h3>
                                                    <ul class="micro-collection-list">
    <?php $lastRelationTypeHeader = $relation->getRelationType()->getTypeName() ?>
    <?php endif; ?>

                                                    <li>
                                                        <a href="<?php echo url_for('CollectionShow', array('uin' => $relation->getRelatedItem()->getUin())) ?>">
            <?php echo $relation->getRelatedItem() ?>
                                                </a>
                                            </li>
                                
<?php endforeach; ?>
<?php if ($lastRelationTypeHeader != ''): ?>
                                                        </ul>
<?php endif; ?>

<?php $lastRelationTypeHeader = '' ?>
<?php foreach ($collection_item->getRelatingCollectionsSorted() as $relation): ?>
<?php if ($lastRelationTypeHeader != $relation->getRelationType()->getNameInverse()): ?>

<?php if ($lastRelationTypeHeader != ''): ?>
                                                                    </ul>
<?php endif; ?>
                                                                    <h3><?php echo $relation->getRelationType()->getNameInverse() ?></h3>
                                                                    <ul class="micro-collection-list">
    <?php $lastRelationTypeHeader = $relation->getRelationType()->getNameInverse() ?>
    <?php endif; ?>

                                                                    <li>
                                                                        <a href="<?php echo url_for('CollectionShow', array('uin' => $relation->getThisItem()->getUin())) ?>">
            <?php echo $relation->getThisItem() ?>
                                                                </a>
                                                            </li>




    <?php endforeach; ?>
    <?php if ($lastRelationTypeHeader != ''): ?>
                                                                    </ul>
<?php endif; ?>
<?php else: ?>
                                                                            <p class="empty-block-message">This collection does not have any related collections</p>
<?php endif; ?>
                                                                            </div>
<?php if (sfConfig::get('app_collection_enable_resources')): ?>
                                                                                <div class="show-block resources-show-block">
                                                                                    <h2>Resources</h2>
    <?php if ($collection_item->getCollectionResources()->count() > 0): ?>

                                                                                    <ul>
        <?php foreach ($collection_item->getCollectionResources() as $resource): ?>
                                                                                        <li>
                                                                                            <a href="<?php echo url_for('DownloadResource', array('uin' => $resource->getUin())) ?>"><?php echo $resource ?></a>
                                                                                        </li>
        <?php endforeach; ?>
                                                                                    </ul>

    <?php else: ?>
                                                                                            <p class="empty-block-message">This collection does not have any resources</p>
    <?php endif; ?>
                                                                                        </div>
<?php endif; ?>
                                                                                            <div class="show-block details-show-block">
                                                                                                <h2>Details</h2>
                                                                                                <table class="prop-display-listing">
                                                                                                    <tbody>
                                                                                                        <tr>
                                                                                                            <th>Locator</th>
                                                                                                            <td>
                                                                                                                <a href="<?php echo url_for('CollectionURI', array('uin' => $collection_item->getUin()), true) ?>">
                        <?php echo url_for('CollectionURI', array('uin' => $collection_item->getUin()), true) ?>
                                                                                        </a>
                                                                                    </td>
                                                                                </tr>
                                                                                <tr>
                                                                                    <th>Collection Type</th>
                                                                                    <td><?php echo $collection_item->getCollectionType() ?></td>
                                                                                </tr>
            <?php if ($collection_item->getVisibilityLevelUin()): ?>
                                                                                                <tr>
                                                                                                    <th>Visibility</th>
                                                                                                    <td><?php echo $collection_item->getVisibilityLevel() ?></td>
                                                                                                </tr>
            <?php endif; ?>
                                                                                                <tr>
                                                                                                    <th>Tags</th>
                                                                                                    <td>
                                                                                                        <a href="<?php echo url_for('TagBrowse', array('tags' => $collection_item->getTagString())) ?>">
                        <?php echo $collection_item->getTagString() ?>
                                                                                            </a>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <th>Metadata Created</th>
                                                                                        <td><?php echo $collection_item->getCreatedAt() ?></td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <th>Metadata Updated</th>
                                                                                        <td><?php echo $collection_item->getUpdatedAt() ?></td>
                                                                                    </tr>

                                                                                </tbody>
                                                                            </table>
                                                                        </div>
                                                                        <div class="context-actions">
                                                                            <ul>
                                                                                <li>
                                                                                    <a class="context-action" href="<?php echo url_for('CollectionEdit', array('uin' => $collection_item->getUin())) ?>">Edit</a>
                                                                                </li>
                                                                            </ul>
                                                                        </div>
<?php endif; ?>
<?php slot('sidebar') ?>
<?php if ($collection_item->getDeletedAt() == null): ?>
                                                                                                    <div class="sidebar-block">
                                                                                                        <ul class="navigation-list">
                                                                                                            <li class="navigation-block">
                                                                                                                <a class="context-action" href="<?php echo url_for('CollectionEdit', array('uin' => $collection_item->getUin())) ?>">Edit this Item</a>
                                                                                                            </li>
                                                                                                        </ul>
                                                                                                    </div>
<?php endif; ?>
<?php end_slot(); ?>